package com.neuedu.mybatis;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.neutech.po.User;

/**
 * Hello world!
 *
 */
public class App 
{
	
		// 根据id查询用户信息，得到一条记录结果
		public static void main(String[] args)throws Exception {
	         // 1. 根据SqlMapConfig.xml，读取资源
	         InputStream inputStream = Resources.getResourceAsStream("config/SqlMapConfig.xml");
	         // 2. 创建SqlSessionFactory，根据全局配置文件SqlMapConfig.xml创建工厂
	         SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
	         // 3. 创建SqlSession
	         SqlSession sqlSession = sqlSessionFactory.openSession();
	         // 4. 使用SqlSession，执行数据库操作
	         User user = sqlSession.selectOne("test.findUserById", 1);
	         System.out.println(user);
	         // 5. 释放资源
	         sqlSession.close();
		}
	
}
